<?php

namespace User\Factory\Form;

use Zend\ServiceManager\FactoryInterface;
use Zend\ServiceManager\ServiceLocatorInterface;
use User\Form\RegisterForm;
use User\Form\RegisterFilter;
use User\Validator\NoRecordExists;
use User\Options;


class RegisterFormFactory implements  FactoryInterface
{
    /**
     * {@inheritDoc}
     */
    public function createService(ServiceLocatorInterface $serviceManager)
    {
        $options = $serviceManager->get('user_module_options');

        $userMapper = $serviceManager->get('user_mapper');


        $emailValidator = new NoRecordExists(array(
            'mapper' => $userMapper,
            'key' => 'email',
        ));

        //var_dump($emailValidator);
        $inputFilter = new RegisterFilter($emailValidator, $options);

        $form = new RegisterForm('register' , $options);
        $form->setInputFilter($inputFilter);

        return $form;
    }
} 
